package com.ewili.x.special.dao.inter;

import com.ewili.x.special.entity.ResearchReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author wonder
 */
public interface ResearchReportDao extends JpaRepository<ResearchReport, Long> {

    boolean existsByCodeAndDateAndAuthor(String s, Date datetime, String author);


    List<ResearchReport> findByCodeAndDate(String code, Date date);

    /**
     * 分析师研报首次买入或者更高评级
     * 利多
     * +x
     *
     * @param code
     * @param date
     * @return
     */
    @Query(value = "select count(1) from research_report where (srating_name=\"强烈推荐\" or srating_name=\"强推\" or srating_name=\"买入\") and changes=\"首次\" and code=?1 and date_format(date,'%Y-%m-%d') = date_format(?2,'%Y-%m-%d')", nativeQuery = true)
    double reportBuyOrHigherAndFirst(String code, Date date);

    /**
     * 分析师研报调高买入或者更高评级
     *
     * @param code
     * @param date
     * @return
     */
    @Query(value = "select count(1) from research_report where (srating_name=\"强烈推荐\" or srating_name=\"强推\" or srating_name=\"买入\") and changes=\"调高\" and code=?1 and date_format(date,'%Y-%m-%d') = date_format(?2,'%Y-%m-%d')", nativeQuery = true)
    double reportBuyOrHigherAndUpper(String code, Date date);

}
